/**
  * @param {string} paragraph
  * @param {string[]} banned
  * @return {string}
*/
var mostCommonWord = function(paragraph, banned) {
  const reg = /[a-zA-Z]+/g, word = [], map = new Map();
  paragraph.replace(reg, function(...payload) {
    word.push(payload[0]);
  });
  word.forEach(item => {
    item = item.toLowerCase();
    if(map.has(item)) {
      map.set(item, map.get(item) + 1);
    } else {
      map.set(item, 1);
    }
  });
  let arr = [...map].sort((a, b) => b[1] - a[1]);
  for(let i = 0; i < arr.length; i++) {
    if(!banned.includes(arr[i][0])) return arr[i][0];
  }
};
let paragraph = "Bob hit a ball, the hit BALL flew far after it was hit.", banned = ["hit"];
console.log(mostCommonWord(paragraph, banned));
